package world.map;

import java.util.Map;

import world.Chunk;
import world.ChunkBlock;
import world.World;

public abstract class ChunkProvider {
	protected World world;
	protected Map<Integer, Chunk> chunkMap;

	public abstract boolean exist(int indexX, int indexZ);

	public abstract Chunk create(int indexX, int indexZ);

	public abstract Chunk loadChunk(int indexX, int indexZ);
	
	public abstract Chunk loadChunks(int indexX, int indexZ);
	
	public abstract Chunk loadChunks(float posX, float posY, float poxZ);
	
	public ChunkBlock findBlock(float x, float y, float z) {
		int chunkIndexX = (int) Math.floor(x / Chunk.SIZE);
		int chunkIndexZ = (int) Math.floor(z / Chunk.SIZE);
		//int chunkID = Chunk.getID(chunkIndexX, chunkIndexZ);
		
		Chunk currentChunk = loadChunk(chunkIndexX,chunkIndexZ);
		int bitmask = 0b1111;
		int posInChunkX = ((int) (x/ ChunkBlock.SIZE))& bitmask;
		int posInChunkZ = ((int) (z/ ChunkBlock.SIZE))& bitmask;
		int posInChunkY = ((int) (y/ ChunkBlock.SIZE))& bitmask;

		return currentChunk.findBlock(posInChunkX, posInChunkY, posInChunkZ);
	}
}
